/*
 * @Author: your name
 * @Date: 2021-09-15 21:37:59
 * @LastEditTime: 2021-10-25 21:33:41
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \henghuisheng\utils\request.js
 */
import Request from 'luch-request'
import BASE_API from '../config.js'
const request = new Request({
	baseURL: BASE_API,
	timeout: 6000,
	header: {
		'Content-type': 'application/x-www-form-urlencoded',
	},
});
//请求拦截器
request.interceptors.request.use((config) => { // 可使用async await 做异步操作
	
	return config
}, config => { // 可使用async await 做异步操作
	// uni.hideLoading();
	return Promise.reject(config)
})

//响应拦截器
request.interceptors.response.use((response) => {
	// uni.hideLoading();
	if (response.data.code == 200) {
		return response.data;
	} else if (response.data.code == 4000) {
		 
		 
		return Promise.reject();

	} else {
		tool.showToast(response.data.msg, 2000, 'none');
		return Promise.reject(response);
	}
	return response
}, (response) => {
	/*  对响应错误做点什么 （statusCode !== 200）*/
	// uni.navigateTo({
	// 	url: '/pages/noNetwork/index'
	// });
	tool.showToast('服务器错误！', 2000, 'error');
	return Promise.reject(response)
})
  
export default request;
